﻿Public Class ucPopupOfficer
    Inherits System.Web.UI.UserControl

	Public ReadOnly Property OfficerId As String
		Get
			Return Me.hfOfficerId.Value
		End Get
	End Property

	Public ReadOnly Property OfficerAppId As String
		Get
			Return Me.lblOfficerAppId.Text
		End Get
	End Property

	Public ReadOnly Property OfficerName As String
		Get
			Return Me.lblOfficerName.Text
		End Get
	End Property

	Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
		Dim userinfo As Entity.UserInfoItem = GlobalApp.Authen
		If Not userinfo.role_id.Equals("1") Then
			imgSponsorPopup.Visible = True
		Else
			imgSponsorPopup.Visible = False
			Me.lblOfficerAppId.Text = userinfo.user_id
			Me.lblOfficerName.Text = userinfo.fullname
			Me.hfOfficerId.Value = userinfo.offcier_id
		End If
	End Sub

	Protected Sub btnSponsorSearch_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSponsorSearch.Click
		If HttpContext.Current.User.IsInRole("admin") Then
			Me.gvOffical.DataSource = BL.Officer.SearchSponser_Staff(Me.txtSearchSponsor.Text)
		Else
			Me.gvOffical.DataSource = BL.Officer.SearchSponser_Member(Me.txtSearchSponsor.Text, GlobalApp.Authen.offcier_id)
		End If
		Me.gvOffical.PageIndex = 0
		Me.gvOffical.DataBind()
		Me.mpu.Show()
		Me.Session("sponsorsearch" & Me.ClientID) = Me.gvOffical.DataSource
	End Sub

	Protected Sub gvOffical_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvOffical.PageIndexChanging
		Me.gvOffical.DataSource = Me.Session("sponsorsearch" & Me.ClientID)
		Me.gvOffical.PageIndex = e.NewPageIndex
		Me.gvOffical.DataBind()
		Me.mpu.Show()
	End Sub

	Protected Sub gvOffical_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvOffical.RowCommand
		If e.CommandName.Equals("Select") Then
			Dim gvRow As GridViewRow = gvOffical.Rows(e.CommandArgument)
			Dim oj As LinkButton = gvRow.Cells(0).Controls(0)
			Me.lblOfficerAppId.Text = oj.Text
			Me.lblOfficerName.Text = gvRow.Cells(1).Text & " " & gvRow.Cells(2).Text
			Me.hfOfficerId.Value = Me.gvOffical.DataKeys(e.CommandArgument).Item(0).ToString
			Me.mpu.Hide()
		End If
	End Sub

End Class